<template lang="pug">
    skin(@up="up",@down="down",@yes="yes",@back="back",@duringUp="up",@duringDown="down")
        div(class="flex-column")
            div(class="flex-column-item flex-row")
                div(class="flex-row-item flex-center-center flex-7") ----警示设置----
                div(class="flex-row-item") {{activeId+1}}
            div(class="flex-column-item flex-center flex-3")
              div(class="flex-row")
                  div(class="flex-row-item flex-7",style="height:100%")
                      div(class="flex-column")
                        div(class="flex-column-item",v-for="(menu,index) in currentPageMenus")
                          div(class="flex-row")
                            div(class="flex-row-item flex-7")
                              span(class="iconfont",:style="{'visibility': index == currentMenuIndex ? 'visible' : 'hidden'}") &#xe62c;
                              span {{menu.name}}
                            div(class="flex-row-ietm center flex-1",v-if="!menu.to")
                              control-select(v-model="currentPageMenus[index]", :ref="'ref' + menu.id", :working="menu.working")
                              span {{menu.unit}}

                  div(class="flex-row-item right",style="height:100%")
                    control-line(:total="menus.length",:current="activeId",style="float:right;")
</template>

<script>

    import MenuList from '@/mixins/MenuList';

    export default {
        mixins:[MenuList],
        data() {
            return {
                page: { maxResultCount: 3 },
                menus: [
                    {
                        name: "蜂鸣报警:",
                        id: 0,
                        working:false,
                        showModal: true,
                        value: window.machine.warning.voice,
                        options: [{name: "开", value: true}, {name: "关", value: false}],
                        onChange(model) {
                            window.machine.warning.voice = model.value;
                        }
                    },
                    {
                        name: "按键声音:",
                        id: 1,
                        working:false,
                        showModal: true,
                        value: window.machine.warning.buttonVoice,
                        options: [{name: "开", value: true}, {name: "关", value: false}],
                        onChange(model) {
                            window.machine.warning.buttonVoice = model.value;
                        }
                    },
                    {
                        name: "用餐提示:",
                        id: 2,
                        working:false,
                        showModal: true,
                        value: window.machine.warning.foodWarning,
                        options: [{name: "开", value: true}, {name: "关", value: false}],
                        onChange(model) {
                            window.machine.warning.foodWarning = model.value;
                        }
                    },
                    {
                        name: "测血糖提示:",
                        id: 3,
                        working:false,
                        showModal: true,
                        value: window.machine.warning.blood,
                        options: [{name: "开", value: true}, {name: "关", value: false}],
                        onChange(model) {
                            window.machine.warning.blood = model.value;
                        }
                    }
                ]
            };
        },

        computed:{
            currentMenuRef(){
                return "ref" + this.currentMenu.id
            }
        },
        methods: {
            up() {
                if (this.currentMenu.working) {
                    this.$refs[this.currentMenuRef][0].up();
                    return;
                }
                this.activeId --;

            },
            down() {
                if (this.currentMenu.working) {
                    this.$refs[this.currentMenuRef][0].down();
                    return;
                }

                this.activeId ++;
            },

            back() {
                if (this.currentMenu.working) {
                    this.currentMenu.working =false;
                } else {
                    this.$router.push("/machine-setting?index=2");
                }
            },
            yes() {
                this.currentMenu.working = !this.currentMenu.working;
            }
        }
    };
</script>

<style lang="less">
</style>
